<template>
	<view>
		<u-form-item label="一级品类:" prop="category_one_id" ref="item1" labelWidth="100px" :required="true"
			borderBottom>
			<view class="zanwei w100">
				<zxz-uni-data-select v-model="category_one_id" :localdata="options.onePinleiList"
					dataKey="name" dataValue="category_id" :multiple="false" placeholder="请选择商品分类"
					@change="getOneBian()"></zxz-uni-data-select>
			</view>
		
		</u-form-item>
		<u-form-item label="二级品类:" prop="category_two_id" ref="item1" labelWidth="100px" :required="true"
			borderBottom>
			<view class="zanwei w100">
				<zxz-uni-data-select v-model="category_two_id" :localdata="options.twoPinleiList"
					dataKey="name" dataValue="category_id" :multiple="false" placeholder="请选择商品分类"
					@change="getTwoBian()"></zxz-uni-data-select>
			</view>
		</u-form-item>
		<u-form-item label="三级品类:" prop="category_three_id" ref="item1" labelWidth="100px" :required="true"
			borderBottom>
			<view class="zanwei w100">
				<zxz-uni-data-select v-model="category_three_id" :localdata="options.threePinleiList"
					dataKey="name" dataValue="category_id" :multiple="false"
					placeholder="请选择商品分类"></zxz-uni-data-select>
			</view>
		</u-form-item>
	</view>
</template>

<script>
	export default {
		props: {
			
		},
		data() {
			return {
				options: {
					onePinleiList: [],
					twoPinleiList: [],
					threePinleiList: [],
				},
				category_one_id:'',
				category_two_id:'',
				category_three_id:'',
			}
		},
		created() {
			this.getcategory(0, 1);
		},
		methods: {
			getOneBian(v) {
				this.getcategory(this.category_one_id, 2);
			},
			getTwoBian(v) {
				this.getcategory(this.category_two_id, 3);
			},
			async getcategory(category_id, index) {
				let {
					code,
					data,
					msg
				} = await this.beg.request({
					url: '/admin/product.Place/getCategory',
					method: 'POST',
					data: {
						category_id: category_id,
					},
				})
				if (code == 1) {
					if (index == 1) {
						this.options.onePinleiList = data.category_infos;
						this.options.twoPinleiList = [];
						this.options.threePinleiList = [];
					}
					if (index == 2) {
						this.options.twoPinleiList = data.category_infos;
						this.options.threePinleiList = [];
					}
					if (index == 3) {
						this.options.threePinleiList = data.category_infos;
					}
				} else {
					uni.$u.toast(msg)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.zanwei {
		height: 100rpx;
		display: flex;
		align-items: center;
	}
</style>